home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Views / Standard Views / ListView.cp < prev    next >
Text File  |  1997-06-28  |  3KB  |  149 lines

  1. // ListView.cp
  2.  
  3. #ifndef ListView_h
  4. #include "ListView.h"
  5. #endif
  6. #ifndef ViewMap_h
  7. #include "ViewMap.h"
  8. #endif
  9. #ifndef ViewCell_h
  10. #include "ViewCell.h"
  11. #endif
  12.  
  13. ListView::ListView()
  14.   : cellHeight( 0 ),
  15.      cellCount( 0 )
  16.   {
  17.   }
  18.  
  19. Rectangle ListView::CellArea( const ViewMap& map, uint32 cell ) const
  20.   {
  21.     Assert( cellHeight > 0 );
  22.     Assert( cell < cellCount );
  23.  
  24.     return Rectangle( map.Bounds().left,
  25.                             map.Bounds().top + cell * cellHeight,
  26.                             map.Bounds().right,
  27.                             map.Bounds().top + cell * cellHeight + cellHeight );
  28.   }
  29.  
  30. Rectangle ListView::CellArea( const ViewMap& map, Range<uint32> cells ) const
  31.   {
  32.     Assert( cellHeight > 0 );
  33.     Assert( cells.End() <= cellCount );
  34.  
  35.     return Rectangle( map.Bounds().left,
  36.                             map.Bounds().top + cells.Start() * cellHeight,
  37.                             map.Bounds().right,
  38.                             map.Bounds().top + cells.End() * cellHeight );
  39.   }
  40.  
  41. Rectangle ListView::UnusedArea( const ViewMap& map ) const
  42.   {
  43.     return Rectangle( map.Bounds().left,
  44.                             map.Bounds().top + cellCount * cellHeight,
  45.                             map.Bounds().right,
  46.                             map.Bounds().bottom );
  47.   }
  48.  
  49. void ListView::Draw( const ViewMap& toDraw ) const
  50.   {
  51.     Assert( cellHeight > 0 );
  52.     
  53.     uint32 index = PixelToCell( toDraw.VisibleBounds().top - toDraw.Bounds().top );
  54.     
  55.     Rectangle area( CellArea( toDraw, index ) );
  56.  
  57.       {
  58.         ViewMap cellMap( toDraw );
  59.     
  60.         while ( index < cellCount && area.top < toDraw.VisibleBounds().bottom )
  61.           {
  62.             cellMap.Set( toDraw, area );
  63.             (*this)[index].Draw( cellMap );
  64.             
  65.             index++;
  66.             area += PointObject( 0, cellHeight );
  67.           }
  68.       }
  69.     
  70.     area.bottom = toDraw.Bounds().bottom;
  71.     toDraw.Erase( area );
  72.   }
  73.  
  74. void ListView::SetCellHeight( uint32 height )
  75.   {
  76.     cellHeight = height;
  77.     Assert( CanMultiply( cellHeight, cellCount ) );
  78.     View::Invalidate();
  79.   }
  80.  
  81. void ListView::AddedCells( Range<uint32> range )
  82.   {
  83.     Assert( CanAdd( range.Length(), cellCount ) );
  84.     cellCount += range.Length();
  85.     Assert( CanMultiply( cellHeight, cellCount ) );
  86.     Invalidate( Range<uint32>( range.Start(), cellCount ) );
  87.   }
  88.  
  89. void ListView::RemovedCells( Range<uint32> range )
  90.   {
  91.     Assert( range.End() <= cellCount );
  92.     Invalidate( Range<uint32>( range.Start(), cellCount ) );
  93.     cellCount -= range.Length();
  94.   }
  95.  
  96. void ListView::Update( uint32 cell ) const
  97.   {
  98.     if ( !Mapped() )
  99.         return;
  100.  
  101.     ViewMap map( *this );
  102.     View::Update( CellArea( map, cell ) );
  103.   }
  104.  
  105. void ListView::Redraw( uint32 cell ) const
  106.   {
  107.     if ( !Mapped() )
  108.         return;
  109.  
  110.     ViewMap map( *this );
  111.     View::Redraw( CellArea( map, cell ) );
  112.   }
  113.  
  114. void ListView::Invalidate( uint32 cell ) const
  115.   {
  116.     if ( !Mapped() )
  117.         return;
  118.  
  119.     ViewMap map( *this );
  120.     map.Invalidate( CellArea( map, cell ) );
  121.   }
  122.  
  123. void ListView::Update( Range<uint32> range ) const
  124.   {
  125.     if ( !Mapped() )
  126.         return;
  127.  
  128.     ViewMap map( *this );
  129.     View::Update( CellArea( map, range ) );
  130.   }
  131.  
  132. void ListView::Redraw( Range<uint32> range ) const
  133.   {
  134.     if ( !Mapped() )
  135.         return;
  136.  
  137.     ViewMap map( *this );
  138.     View::Redraw( CellArea( map, range ) );
  139.   }
  140.  
  141. void ListView::Invalidate( Range<uint32> range ) const
  142.   {
  143.     if ( !Mapped() )
  144.         return;
  145.  
  146.     ViewMap map( *this );
  147.     map.Invalidate( CellArea( map, range ) );
  148.   }
  149.